package com.szbmyoubao.app.ui.main.mine

import com.szbmyoubao.app.http.request
import com.szbmyoubao.app.storage.UserStorage
import com.ellecity06.common.base.BaseMviViewModel
import com.ellecity06.common.ktx.postEvent

/**
 * @author ellecity06
 * @time 2024/10/22 14:49
 * @des
 */
class MineViewModel : BaseMviViewModel<MineState, MineIntent>() {
    override suspend fun collectIntent(it: MineIntent) {
        when (it) {
            MineIntent.FetchLastVersion -> {}
            MineIntent.FetchUserInfo -> {
                fetchUserInfo()

            }

            MineIntent.Logout -> {}

        }
    }







    private fun fetchUserInfo() {
        request(api = { userInfo() }, error = { postState(MineState.RefreshFinish) }, success = {
            it?.let {
                UserStorage.Companion.user = it
                mState.postEvent(MineState.UserInfoSuccess(it), MineState.RefreshFinish)
            }

        })

    }
}